//
//  WealthTableCell.m
//  UI_Project_A
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 GH. All rights reserved.
//

#import "WealthTableCell.h"
#import "ModelOfData.h"
#import <UIImageView+WebCache.h>
#import <DKNightVersion.h>

#define WIDTH  self.frame.size.width
@interface WealthTableCell ()

@property (nonatomic ,retain)UILabel *label;
@property (nonatomic ,retain)UIImageView *imageViewOne;
@property (nonatomic ,retain)UIImageView *imageViewTwo;
@property (nonatomic ,retain)UIImageView *imageViewThree;

@end

@implementation WealthTableCell

- (void) dealloc {
    [_label release];
    [_imageViewOne release];
    [_imageViewThree release];
    [_imageViewTwo release];
    [super dealloc];

}





- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {


    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createImageview];
        [self createLabel];
    }


    return self;
}




#pragma mark - label
- (void)createLabel {
    
    self.label = [[UILabel alloc]init];
    [self addSubview:self.label];
  
    [self.label release];
    
    self.label.numberOfLines = 0;
self.label.dk_textColorPicker = DKColorWithColors([UIColor colorWithWhite:0.247 alpha:1.000],[UIColor whiteColor]);
 
    
}


- (void)passDataWithModl:(ModelOfData *)model {


    self.label.text = model.title;

     NSArray *arr = model.imageurls;

    //1
  NSString *str1 = [self Substring:[arr[0] objectForKey:@"url"]];
    [self.imageViewOne sd_setImageWithURL:[NSURL URLWithString:str1]];
    
    //2
    NSString *str2 = [self Substring:[arr[1] objectForKey:@"url"]];
     [self.imageViewTwo sd_setImageWithURL:[NSURL URLWithString:str2]];
   
    //3
    NSString *str3 = [self Substring:[arr[2] objectForKey:@"url"]];
    [self.imageViewThree sd_setImageWithURL:[NSURL URLWithString:str3]];
    

}

#pragma mark - 图片Url截取
- (NSString *)Substring:(NSString *)urlString {
    
    
    NSString *sub = urlString;
    
    if ([sub isEqualToString:@""]) {
        return nil;
    }
    
    
    if ([sub hasSuffix:@"jpg"]) {
        return urlString;
    }
    else {
        
        NSRange range = [urlString rangeOfString:@"u="];
        
        NSString *sub1 = [urlString substringFromIndex:range.location+2];
        
        NSRange lastRange = [sub1 rangeOfString:@"&"];
        sub = [sub1 substringToIndex:lastRange.location];
        
    }
    
    return sub;
}









- (void)createImageview {
    self.imageViewOne = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    
    [self addSubview:self.imageViewOne];
    [self.imageViewOne release];
    
    
    //Two
    self.imageViewTwo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    [self addSubview:self.imageViewTwo];
    [self.imageViewTwo release];

    
   //Three
    self.imageViewThree = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    [self addSubview:self.imageViewThree];
    [self.imageViewThree release];

    
    
}



- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    
    self.label.frame = CGRectMake(5, 5, self.frame.size.width - 10, 22);
   
    self.imageViewOne.frame = CGRectMake(10, 35, (WIDTH - 40)/3,self.frame.size.height - 32);
    
    self.imageViewTwo.frame = CGRectMake(20 + (WIDTH - 40)/3, 35, (WIDTH - 40)/3,self.frame.size.height - 32);
    
    self.imageViewThree.frame = CGRectMake(30 + (WIDTH - 40)/3 *2, 35, (WIDTH - 40)/3,self.frame.size.height - 32);
    
}











- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
